package psd.scala.rules
import scala.collection.mutable
import scala.collection.JavaConversions._
import psd.model.Bug
import psd.scala.FactDb
import psd.scala.facts.ClassDefT
import psd.scala.facts.FieldDefT

class AvoidConstantInterface (description: String) extends AbstractRule (description) {
  
  
  def execute(db: FactDb): mutable.ArrayBuffer[Bug]= {
    
   	 val fieldDefTList = db.fieldDefTList
   	 val classDefTlist = db.classDefTList
   	 
   	 val result = new mutable.ArrayBuffer[Bug]
   	 
   	   	 for ( cd <- classDefTlist ) {
   	   	   if (cd.isInterface){
   	   	   		val fields = fieldDefTList.filter(_.path.equals(cd.path))
   	   				for (fd <- fields) {
   	   					 val bug = new Bug
					     bug.set_lineNumber(fd.line.toInt)
					     bug.set_path(cd.path)
				    	 bug.set_ruleName(this.getClass().toString())
				    	 bug.set_description(this.description)
				    	 result+=bug
   	   				}
   	   	   }
	   	 }
	   	 return result
	  }
  
}